<template>
  <div class="container">
    <el-row class="table-top">
      <div class="left">
        <el-input v-model="seachValue.code" placeholder="请输入项目编号" clearable @input="changeSeach" />
        <el-select v-model="seachValue.category" placeholder="全部类别" style="width: 100%;margin-left: 10px" clearable @change="changeSeach">
          <el-option key="Operation" label="Operation" value="Operation" />
          <el-option key="Nondeliverable" label="Nondeliverable" value="Nondeliverable" />
          <el-option key="Deliverable" label="Deliverable" value="Deliverable" />
        </el-select>
      </div>
      <div class="right">
        <el-button v-permission="['80002']" type="primary" @click="openFrom">创建项目</el-button>
      </div>
    </el-row>
    <el-table v-permission="['80001']" :data="tableData" style="width: 100%" :header-cell-style="{background:'#F7F8FA'}">
      <el-table-column prop="engagement_code" align="center" label="项目编号" />
      <el-table-column prop="engagement_code_desc" align="center" label="项目说明" show-overflow-tooltip />
      <el-table-column prop="category" align="center" label="类别" />
      <el-table-column prop="department.department_name" align="center" label="归属部门" />
      <el-table-column prop="cc_rate" align="center" label="CCRatio" />
      <el-table-column prop="oc_rate" align="center" label="OCRatio" />
      <el-table-column prop="owner.name" align="center" label="项目负责人" />
      <el-table-column prop="hr.name" align="center" label="HRBP" />
      <el-table-column prop="team_leader.name" align="center" label="团队负责人" />
      <el-table-column prop="finance.name" align="center" label="财务" />
      <el-table-column align="center" label="操作" width="120">
        <template slot-scope="scope">
          <el-button v-permission="['80003']" type="text" size="small" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button v-permission="['80004']" type="text" size="small" @click="handleDeleta(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- <div class="broadfun_block">
      <el-pagination
        :current-page="seachValue.pagenum"
        :page-sizes="[10, 20, 50]"
        :page-size="seachValue.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      />
    </div> -->

    <ProjectFrom :id="editId" ref="ProjectFrom" :visible="visible" :form="editFrom" @close="closeFum" @success="successFun" />
  </div>
</template>

<script>
import ProjectFrom from './components/ProjectFrom'
import { getEngagementCode, deleteEngagementCode } from '@/api/base'
export default {
  name: 'Base',
  components: {
    ProjectFrom
  },
  data() {
    return {
      pageNum: 1,
      pageSize: 10,
      total: 0,
      seachValue: {
        pagenum: 1,
        pagesize: 10,
        code: '',
        category: ''
      },
      visible: false,
      editId: 0,
      editFrom: {},
      test: '',
      tableData: []
    }
  },
  async mounted() {
    this.init()
  },
  methods: {
    async init() {
      const res = await getEngagementCode(this.seachValue)
      if (res.ret === 0 && res.data.length) {
        this.tableData = res.data
      } else {
        this.tableData = []
      }
    },
    async handleDeleta(row) {
      const isDelete = await this.$confirm(`确定删除`, '提示', { type: 'warning' })
      if (!isDelete) {
        return
      }
      const res = await deleteEngagementCode(row.ID)
      if (res.ret === 0) {
        this.$message.success('删除成功')
        this.init()
      }
    },
    handleEdit(row) {
      this.editId = row.ID
      this.editFrom = JSON.parse(JSON.stringify(row))
      this.visible = true
    },
    changeSeach() {
      this.init()
    },
    openFrom() {
      this.editId = 0
      this.visible = true
    },
    successFun() {
      this.visible = false
      this.init()
    },
    closeFum() {
      this.visible = false
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
